package com.jiangkai.common.shiro.rediscache.impl;

import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;

import javax.annotation.Resource;

import org.apache.log4j.Logger;
import org.apache.shiro.cache.Cache;
import org.apache.shiro.cache.CacheException;
import org.apache.shiro.cache.CacheManager;

import com.jiangkai.common.redis.RedisDao;
import com.jiangkai.common.shiro.rediscache.RedisCache;

/**
 * 
 * @author jiangkia
 *
 */
public class RedisCacheManager implements CacheManager{
	 private static final Logger logger = Logger.getLogger(RedisCacheManager.class);

	    private final ConcurrentMap<String, Cache> caches = new ConcurrentHashMap<String, Cache>();

	    @Resource
	    private RedisDao redisDao;
	   
	public <K, V> Cache<K, V> getCache(String name) throws CacheException {
		 logger.debug("获取名称为: " + name + " 的RedisCache实例");
		  Cache c = caches.get(name);
	        if (c == null) {
	            c = new RedisCache<K, V>(redisDao);
	            caches.put(name, c);
	        }
	        return c;
	}

}
